import Vue from 'vue'
import Vuex from 'vuex'
import {getlist} from '../api/index'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],
    item:{},
  },
  mutations: {
    SET_LIST(state, data){
      state.list = data
    },
    SET_DETAIL(state,data){
      const id = data.id
      state.item = state.list.filter(v=>v.id === id)
    },
    SET_SEARCH(state,data){
      let newList = []
      // console.log(data);
      newList = state.list.filter(item => item.title.includes(data))
      state.list = newList
    }
  },
  actions: {
    GET_LIST(contxt,data){
      getlist().then(res=>{
        //  console.log(res.data.list);
         contxt.commit("SET_LIST",res.data.list)
       })
    }
  },
  modules: {
  }
})
